package com.china08.yxyapi.api.comm.weike;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.YxyResSubjectRepository;

/**
 * 微课公共接口---根据学段查询微课的科目
 * 
 */
@CrossOrigin
@RestController
public class WeikeSubController {

    @Autowired
    private YxyResSubjectRepository yxyResSubjectRepository;

    @RequestMapping(value = "/api_yw/comm/weike/subject", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object process(@RequestParam(value = "stage", required = true) String stage) {

        List<RespModel> list = new ArrayList<RespModel>();
        List<Object[]> list2 = yxyResSubjectRepository.findSubject(stage);
        if (CollectionUtils.isNotEmpty(list2)) {
            RespModel respModel = null;
            for (Object[] objects : list2) {
                respModel = new RespModel();
                respModel.subjectId = (String) objects[0];
                respModel.subjectName = (String) objects[1];
                list.add(respModel);
            }
        }
        return list;
    }

    protected static class RespModel extends YxyApiRespModel {

        public String subjectId;// 科目id

        public String subjectName;// 科目名称
    }

}
